package zzps.exeed.kernel.pandabuilder;

import zzps.exeed.kernel.core.PandaContainer;
import zzps.exeed.kernel.core.PandaEmbryo;
import zzps.exeed.kernel.holder.PandaHolder;
import zzps.exeed.kernel.annotation.Component;
import zzps.exeed.kernel.tool.StrTool;

import java.util.function.Consumer;

public class ComponentPandaBuilder implements PandaBuilder<Component> {

    @Override
    public void collect(Class<?> target, Component annotation, Consumer<PandaEmbryo> consumer) {
        String name = annotation.name();
        if (StrTool.isEmpty(name)){
            name = target.getCanonicalName();
        }
        PandaEmbryo pandaEmbryo = new PandaEmbryo(name,target, annotation,this);
        consumer.accept(pandaEmbryo);
    }

    @Override
    public void build(PandaEmbryo<Component> pandaEmbryo, Consumer<PandaHolder> consumer, PandaContainer pandaContainer) {
        PandaHolder pandaHolder = new PandaHolder(pandaEmbryo.clazz());
        pandaHolder.setName(pandaEmbryo.name());
        consumer.accept(pandaHolder);
    }
}
